/*
 * @Author: lll 1280388921@qq.com
 * @Date: 2025-08-08 17:56:31
 * @LastEditors: lll 1280388921@qq.com
 * @LastEditTime: 2025-08-14 16:34:34
 * @FilePath: /lesson43/ServerCal.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

#include "TcpServer.hpp"
#include "ServerCal.hpp"
#include "Daemon.hpp"
#include <unistd.h>

using namespace std;

void Usage(const string& proc)
{
    cout<<"\nUsage: "<<proc<<" port\n\n"<<endl;
}

// ./servercal 8080
int main(int argc,char *argv[])
{
    if(argc!=2)
    {
        Usage(argv[0]);
        exit(0);
    }
    uint16_t port=stoi(argv[1]);

    ServerCal cal;
    TcpServer*tsvp=new TcpServer(port,bind(&ServerCal::Calculator,&cal,placeholders::_1));
    tsvp->InitServer();
    // Daemon();
    daemon(0,0);
    tsvp->Start();

    // Response res(1000,0);
    // string text;
    // res.Serialize(&text);

    // cout<<text<<endl;

    // string pakg=Encode(text);
    // cout<<pakg<<endl;

    // cout<<"------------------"<<endl;

    // text="";
    // Decode(pakg,&text);
    // cout<<text<<endl;
    // Response tmp;
    // tmp.Deserialize(text);
    // cout<<tmp.result<<endl;
    // cout<<tmp.code<<endl;


    // Request req(1234,5678,'+');

    // string s;
    // req.Serialize(&s);
    // cout<<s<<endl;

    // s=Encode(s);
    // cout<<s<<endl;

    // cout<<"--------------"<<endl;

    // string text;
    // bool r=Decode(s,&text);
    // cout<<r<<endl;
    // cout<<text<<endl;

    // Request tmp;
    // tmp.Deserialize(text);

    // cout<<tmp.x<<endl;
    // cout<<tmp.y<<endl;
    // cout<<tmp.op<<endl;

    return 0;
}